<template>
  <div id="allocatedManageTopSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <el-form-item label="大鹏号" prop="dpAccount">
          <el-input
            v-model="formInline.dpAccount"
            placeholder="请输入大鹏号"
            clearable
          />
        </el-form-item>
        <el-form-item label="赠送学院" prop="categoryId">
          <el-select v-model="formInline.categoryId" clearable>
            <el-option
              v-for="item in collegeList"
              :key="item.dictLabel"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
         <el-form-item  prop="timeType">
          <el-select v-model="formInline.timeType" clearable>
            <el-option
              v-for="item in checkedTime"
              :key="item.label"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item  prop="createTime">
          <!-- label="创建时间" -->
          <el-date-picker
            @change="confirmDate"
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <!-- <el-form-item label="发放状态" prop="state">
          <el-select v-model="formInline.state" clearable>
            <el-option
              v-for="item in issuedStatusList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="是否确认" prop="state">
          <el-select v-model="formInline.state" clearable>
            <el-option
              style="width:170px"
              v-for="item in isConfirm"
              :key="item.label"
              :label="item.label"
              :value="item.value"
              :title="item.name"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
import { getAwardAll } from '@component/activeManagement/common/js/lableApi' // 导入公用方法
export default {
  name: 'allocatedManageTopSearch',
  msg: '角色管理-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          categoryId:'',/*赠送学院id*/
          checkedCollege:'',
          dpAccount: '', // 用户名称
          state: '', // 发放状态
          timeType:'CONFIRM',
          startTime:'',
          endTime:''
        }
      }
    },
    searchParams:{
      type: Object,
      default: function() {
        return {
          pageNum: 1, // 当前页数
        }
    }
    }
  },
  data() {
    return {
      isConfirm:[
        {
          label:'已确认',
          value:'CONFIRMED'
        },
        {
          label:'未确认',
          value:'UNCONFIRMED'
        },
      ],
      checkedTime:[
         {label:' 导入名单时间',value:'IMPORT'},
         {label:' 确认发放时间',value:'CONFIRM'}
      ],
      dictValue: '',
      collegeList:[],
      // 奖品类型
      prizeTypeList: [],
      // 发放状态
      issuedStatusList: [],
      // 奖项
      awardsList: [],
      createTime: [], // 创建时间
      rules: {
        dpAccount: {},
        state: {},
        categoryId: {},
        timeType:{},
        // awardId: {},
        createTime: { type: 'array' }
      }
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    }
  },
  mounted() {
    this.getStatusList()
    this.getCollegeList()
  },
  methods: {
    confirmDate(val){
      this.formInline.startTime = val[0]
      this.formInline.endTime = val[1]
    },
    async getCollegeList(){
      // 获取学院列表
        let data = await sysNormalDisable(
           'sys_college','sys_college'
        )
        this.collegeList = data
    },
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.searchParams.pageNum = 1
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
    },
    /* 获取奖品类型 */
    async getStatusList() {
      let prize = await sysNormalDisable('prizes_type', 'prizesType')
      this.prizeTypeList = [{ dictLabel: '全部', dictValue: '' }].concat(prize)
      /*获取发放状态 */
      let issuedStatus = await sysNormalDisable('issued_status', 'issuedStatus')
      this.issuedStatusList = [{ dictLabel: '全部', dictValue: '' }].concat(
        issuedStatus
      )
    },
    getAward(id) {
      /*获取奖项状态*/
      let obj = {
        relevanceId: id,
        relevanceType: 'ACTIVITY'
      }
      getAwardAll(obj, (response) => {
        this.awardsList = [{ name: '全部', id: '' }].concat(response)
      })
    },
    setDefault() {
      //默认奖项
      this.awardsList = [{ name: '全部', id: '' }]
    }
  }
}
</script>

<style lang="less" scoped>
#allocatedManageTopSearch {
  .search-box {
    padding-left: 0;
  }
}
</style>
